package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.model.dto.SysCompanyUserDTO;
import com.nineclock.model.dto.SysRegisterDTO;
import com.nineclock.model.dto.SysUserDTO;
import com.nineclock.system.SysUserControllerApi;
import com.nineclock.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class SysUserController implements SysUserControllerApi {

    @Autowired
    SysUserService  sysUserService;

    @GetMapping("/query")
    public Result<SysUserDTO> queryUser(@RequestParam("username") String username){
        SysUserDTO sysUserDTO = sysUserService.queryUser(username);
        if (sysUserDTO==null) {
            return Result.success();
        }
        return Result.success(sysUserDTO);
    }

    /**
     * 用户注册
     * @param sysRegisterDTO
     * @return
     */

    @Override
    @PostMapping("/register")
    public Result register(SysRegisterDTO sysRegisterDTO) {
        Long userId = sysUserService.register(sysRegisterDTO);
        return Result.success(userId);
    }

    @GetMapping("/findById")
    public Result<SysCompanyUserDTO> findUserById(@RequestParam("userId") Long userId){
        SysCompanyUserDTO sysUserDTO = sysUserService.findUserById(userId);
        return Result.success(sysUserDTO);
    }
}
